﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlServerCe;
using System.Collections;
//using System.Windows.Forms;
using System.Data.Common;


namespace ResultsManagementSystem
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
            //SqlCeConnection conn = null;

            //SqlCeEngine engine = new SqlCeEngine("Data Source = Result.sdf");
            //engine.CreateDatabase();

            //建立数据库连接
            //conn = new SqlCeConnection(@"Data Source=../../Results.sdf");
            //conn.Open();

            //创建sql命令
            //SqlCeCommand cmd = conn.CreateCommand();

            //创建表
            //cmd.CommandText = "CREATE TABLE TestTbl(col1 int PRIMARY KEY, col2 ntext, col3 money)";
            //cmd.ExecuteNonQuery();

            //插入数据
            //cmd.CommandText = "INSERT INTO TestTbl(col1, col2, col3) VALUES (10, 'abc', 15.66)";
            //cmd.ExecuteNonQuery();

            //查询数据
            //cmd.CommandText = "SELECT * FROM TestTbl";
            //SqlCeDataReader rdr = cmd.ExecuteReader();

            //while (rdr.Read())
            //{
            //    MessageBox.Show(" col1 = " + rdr.GetInt32(0) +
            //        " col2 = " + rdr.GetString(1) +
            //        " col3 = " + rdr.GetSqlMoney(2));
            //}

            //更新数据
            //cmd.CommandText = "UPDATE TestTbl set col2='some new value' WHERE col1=0";
            //cmd.ExecuteNonQuery();

            //关闭连接
            //conn.Close();
        }

        private void login_Click(object sender, EventArgs e)
        {
            /*获取登陆身份代码
             * 学生：0
             * 教师：1
             * 教务处：2
             * 教务秘书：3
             * 错误：-1
             */
            int characterIndex = this.characterSelect.SelectedIndex;
        }

        private void quit_Click(object sender, EventArgs e)
        {
            //关闭窗口
            this.Close();
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            //获取登陆身份代码
            int characterIndex = this.characterSelect.SelectedIndex;

            //判断登陆类型
            switch (characterIndex)
            {
                case 0:

                    StudentDao studentDao = new StudentDao();

                    Student student = studentDao.querryStudentByName(this.nameText.Text);

                    //判断登陆名和密码
                    if (student != null)
                    {
                        if (this.passwordText.Text != student.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            //test
                            MessageBox.Show("登陆成功！");
                            //test
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }

                    break;
                case 1:

                    TeacherDao teacherDao = new TeacherDao();

                    Teacher teacher = teacherDao.querryTeacherByName(this.nameText.Text);

                    //判断登陆名和密码
                    if (teacher != null)
                    {
                        if (this.passwordText.Text != teacher.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            //test
                            MessageBox.Show("登陆成功！");
                            //test
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }

                    break;
                case 2:
                    break;
                case 3:
                    break;
                default:
                    MessageBox.Show("登陆身份不存在！");
                    break;
            }



        }
    }
}
